﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;


namespace Xiaov.SmartWeb.Application.HXZB
{
    public partial class ZyzbLeftDownData : System.Web.UI.Page
    {
        string zbbm = "", dwbm = "", nf = "", yf = "", type = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                #region 获取参数
                if (Request.QueryString["zbbm"] != null)
                {
                    zbbm = Request.QueryString["zbbm"].ToString();
                }
                if (Request.QueryString["dwbm"] != null)
                {
                    dwbm = Request.QueryString["dwbm"].ToString();
                }
                if (Request.QueryString["nf"] != null && Request.QueryString["yf"] != null)
                {
                    nf = Request.QueryString["nf"].ToString();
                    yf = Request.QueryString["yf"].ToString();
                }
                if (Request.QueryString["type"] != null)//数据信息 标题，本年数据，去年数据
                {
                    type = Request.QueryString["type"].ToString();
                }
                #endregion
                DataTable dt = null;
                switch (zbbm)
                {
                    #region 工业总产值
                    case "TG030003":
                        dt = InitGyzcz();
                        break;
                    #endregion
                    #region 工业销售产值
                    case "TG030004":
                        dt = InitGyxscz();
                        break;
                    #endregion
                    #region 原油产量
                    case "TG030008":
                        dt = InitYycl();
                        break;
                    #endregion
                    #region 天然气产量
                    case "TG030026":
                        dt = InitTrq();
                        break;
                    #endregion
                    #region 利润总额
                    case "TG820013":
                        break;
                    #endregion
                    #region 原油递减率
                    case "TG070031":
                        dt = InitYydjl();
                        break;
                    #endregion
                    #region 能源合计
                    case "NH6111":
                        dt = InitNyhj();
                        break;
                    #endregion
                    default:
                        break;
                }
                #region 输出数据
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (zbbm == "TG070031")//原油递减率
                    {
                        if (type == "title")
                        {
                            Response.Write("子项\t母项");
                        }
                        else if (type == "datas")
                        {
                            Response.Write(dt.Rows[0]["ljzx"].ToString() + "\t");
                            Response.Write(dt.Rows[1]["ljzx"].ToString());
                        }
                    }
                    else
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i]["data"].ToString() == "")
                            {
                                dt.Rows[i]["data"] = 0;
                            }
                            if (type == "title")
                            {
                                if (i != dt.Rows.Count - 1)
                                {
                                    Response.Write(dt.Rows[i]["title"].ToString() + "\t");
                                }
                                else
                                {
                                    Response.Write(dt.Rows[i]["title"].ToString());
                                }
                            }
                            else if (type == "datas")
                            {
                                if (i != dt.Rows.Count - 1)
                                {
                                    Response.Write(dt.Rows[i]["data"].ToString() + "\t");
                                }
                                else
                                {
                                    Response.Write(dt.Rows[i]["data"].ToString());
                                }
                            }
                        }
                    }
                    Response.End();
                }
                #endregion               
            }
        }

        #region 工业总产值
        protected DataTable InitGyzcz()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select XJLJCZ data,zbmc title from tg04_2 t WHERE zbbm in('TG040020002','TG040020003','TG040020004','TG040020005','TG040020006','TG040020007') and nf={1} and yf={0} and dwbm='{2}'");
            DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), yf, nf, "HB")).Tables[0];
            return dt;            
        }
        #endregion

        #region 工业销售产值
        protected DataTable InitGyxscz()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select XJLJXSCZ data,zbmc title from tg04_2 t WHERE zbbm in('TG040020002','TG040020003','TG040020004','TG040020005','TG040020006','TG040020007') and nf={1} and yf={0} and dwbm='{2}'");
            DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), yf, nf, "HB")).Tables[0];
            return dt;
        }
        #endregion

        #region 原油产量
        protected DataTable InitYycl()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@"select bnlj data,b.dwmc title from SC01 a,dwbmb b where a.dwbm=b.dwbm and a.nf={0} and a.yf={1} and a.zbbm='SC010001' and a.dwbm in ({2})");
            DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), nf, yf, "'HB01','HB02','HB03','HB04','HB05'")).Tables[0];
            return dt;
        }
        #endregion

        #region 天然气产量
        protected DataTable InitTrq()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@"select bnlj data,b.dwmc title from SC01 a,dwbmb b where a.dwbm=b.dwbm and a.nf={0} and a.yf={1} and a.zbbm='SC010003' and a.dwbm in ({2})");
            DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), nf, yf, "'HB01','HB02','HB03','HB04','HB05'")).Tables[0];
            return dt;
        }
        #endregion

        #region 原油递减率
        protected DataTable InitYydjl()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select ljzx from TG07 t WHERE zbbm='TG070031' and nf={1} and yf={0} and dwbm='{2}'");
            sbSql.Append(" union all ");
            sbSql.Append("select ljmx from TG07 t WHERE zbbm='TG070031' and nf={1} and yf={0} and dwbm='{2}'");
            DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), yf, nf, "HB")).Tables[0];
            return dt;           
        }
        #endregion

        #region 能源合计
        protected DataTable InitNyhj()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select xhhj data,zbmc title from nh61 t WHERE (zbbm='NH6104' or zbbm='NH6102' or zbbm='NH6105' or zbbm='NH6106' or zbbm='NH6101') and nf={1} and yf={0} and dwbm='{2}'");
            DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), yf, nf, "HB")).Tables[0];
            return dt;
        }
        #endregion
    }
}